//自定义外部js文件

function lastPage(number,isSearch){
	
//	number -= 1;
	var num = parseInt(number);
	num -= 1;
	if(num <= 0){
		alert("已经是第一页了！");
	}else{
		alert(isSearch)
		if(isSearch){
			window.location.href="/HappyPets/SearchServlet?currentPageNumber="+num;
		}else{
			window.location.href="/HappyPets/DogsServlet?currentPageNumber="+num;
		}
		
	}
	
	
}

function nextPage(number,maxNumber,isSearch){
	var num = parseInt(number);
	var maxNum = parseInt(maxNumber);
	num += 1;
	if(num > maxNum){
		alert("已经是最后一页了！");
	}else{
		alert(isSearch)
		if(isSearch){
			window.location.href="/HappyPets/SearchServlet?currentPageNumber="+num;
		}else{
			window.location.href="/HappyPets/DogsServlet?currentPageNumber="+num;
		}
	}
}

function pageSure(maxNumber,isSearch){
	var number = document.getElementById("selectPage").value;
	var num = parseInt(number);
	var maxNum = parseInt(maxNumber);
	if(num > maxNum){
		alert("没有这么多页，请重新输入。");
	}else{
		alert(isSearch)
		if(isSearch){
			window.location.href="/HappyPets/SearchServlet?currentPageNumber="+num;
		}else{
			window.location.href="/HappyPets/DogsServlet?currentPageNumber="+num;
		}
	}
	
}

function pageForward(currentPageNumber,forwardPageNumber,isSearch){
	var c_number = parseInt(currentPageNumber);
	var f_number = parseInt(forwardPageNumber);
	if(c_number != f_number){
		alert(isSearch)
		if(isSearch){
			window.location.href="/HappyPets/SearchServlet?currentPageNumber="+f_number;
		}else{
			window.location.href="/HappyPets/DogsServlet?currentPageNumber="+f_number;
		}
	}
	
}

function keywordSearch(){
	
	var keyword = document.getElementById("keywordSearch").value;
	
	if(keyword != "搜索"){
		window.location.href="dogs.jsp?keywords="+keyword;
	}
	
}


	var cPage = 1;
	function pageFor(cup,fop,flg,map,id){
		var cp = parseInt(cup);
		var fp = parseInt(fop);
		var fg = parseInt(flg);
		var mp = parseInt(map);
		cp = cPage;
		
//		alert(' flag '+fg);
		
		switch(fg){
		case 1:{//up
			if(fp <= 0){
				alert(fp);
			}else{
				cPage --;
				ajaxPage(cPage,id);
			}
			
		}; break;
		case 2:{//down
			
			if(fp > mp){
			}else{
				cPage ++;
				ajaxPage(cPage,id);
			}
		}; break;
		default :{//forward
			
			if(fp > mp){
			}else{
				cPage = fp;
				ajaxPage(cPage,id);
			}
			
		};
		}
		
	}
	
	
	
	function pageFors(map,id){
		var mp = parseInt(map);
		var fp = $(".selectPage").val();
//		alert('pageFors:'+fp);
		cPage = fp;
		if(fp > mp){
			alert('输入有误');
		}else{
			ajaxPage(cPage,id);
		}
	}
	
	function ajaxPage(fp,id){
		
//		alert("fp id"+fp+'---'+id+' cpage '+cPage);
		
		$.getJSON("../AJAXPage.do",{id:id,forwardPage:fp},function(data,status){
			if(status){
				//remove
				$(".cart-header1").remove();
				//add
				for(var i in data){
					var $ul = $("<ul/>").addClass("cart-header1");
					var j = 0;
					$.each(data[i],function(key,val){
						j++;
//						if(j<5){
							var $li = $("<li><span>"+val+"</span></li>");
//						}else{
//							var $li = $('<li><div class="basic" data-average="'+parseInt(val)+'" data-id="1"> </div></li>');
//						}
						
						$ul.append($li);
					});
					$ul.append("<div class='clearfix'> </div>");
					$(".cart-header").after($ul);
				}
				
			}else{
				var $div = $('<div>暂无评论</div>');
				div.append("<div class='clearfix'> </div>");
				$(".cart-header").after($div);
			}
		});
		
		
	}
	
	function dataDeal(data){
		//对data进行处理
		for(var i in data){
			$.each(obj,function(key,val){
				alert(key+'--'+val);
			});
		}
	}


